# include "scene.h"

# ifdef SOLVE_ENERGY
# include <stdio.h>

/* This function determines all the grid-parameters related to the heater which is fixed at the top surface. */
extern short heater_param(struct grid *g)
   {
    unsigned int i;

#   ifdef TRACE_FILE
    fprintf(g->trptr, "Entering into 'heater_param()'...\n");
#   endif

    for(i = NrG; i < NrG+g->nr; i++) if(g->r[i] >= r_HEATER) break;

    if(i == NrG+g->nr)
        {
         g->r_heater = r_CYL;
         g->nr_heater = g->nr;
        }

    else{
         if(g->r[i] - r_HEATER <= r_HEATER - g->r[i-1])
             {
              g->r_heater = g->r[i];
              g->nr_heater = i - NrG;
             }
         else{
              g->r_heater = g->r[i-1];
              g->nr_heater = i - NrG -1;
             }
        }

    fprintf(g->lptr, "\n\n[Heater Parameters]\nr_heater: %E ---> %E\nnr_heater = %d\n", r_HEATER, g->r_heater, g->nr_heater);

#  ifdef CHECK_CONFIG
    printf("\n\n[Heater Parameters]\n\nr_heater: %E ---> %E\nnr_heater = %d\n", r_HEATER, g->r_heater, g->nr_heater);

    printf("\n\tAre the heater parameters reasonable (y/n) ? ");  fflush(stdout);
    if(getchar() != 'y')
           {
            printf("\nWARNING: With the grid-configuration parameters defined in \"scene.h\", proper grid-generation from heater's point of view does not seem to be possible. Re-define those parameters, re-compile, and then run the program again.\n\n");

            while(getchar() != '\n');
            return -1;
           }
    else while(getchar() != '\n');
#   endif

#   ifdef TRACE_FILE
    fprintf(g->trptr, "...'heater_param()' ends.\n");
#   endif

    return 1;
   }

# endif
